package com.maple.soa.lock;

import java.util.concurrent.TimeUnit;

/**
 * volatile使用
 * 1.线程可见性
 * @author lijian
 * @date 2021/4/22 23:54
 */
public class L01_Volatile {
    volatile boolean isRun = true;
    void m() {
        System.out.println("m start.");
        while (isRun) {

        }
        System.out.println("m end.");
    }

    public static void main(String[] args) {
        L01_Volatile v = new L01_Volatile();
        new Thread(v::m, "t1").start();
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        v.isRun = false;
    }
}
